package com.masterclient.app.businessmodule.commonmodule;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselib.widget.navgation.FCNavigationBar;
import com.eoner.managerlibrary.user.UserDataManager;
import com.masterclient.app.R;
import com.masterclient.app.base.FCBusinessActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class UserCheckCacheTestActivity extends FCBusinessActivity {

    @BindView(R.id.user_list_view)
    RecyclerView mRecyclerView;

    private UserCheckAdapter mUserCheckAdapter;
    private List<UserCacheBean>userCacheBeanList = new ArrayList<>();

    @Override
    protected int requireGetLayoutId() {
        return R.layout.activity_user_check_cache_test;
    }

    @Override
    protected void requireSetCustomNavigationBar(FCNavigationBar navigationBar) {
        navigationBar.setTitle("查看用户缓存");
    }

    @Override
    protected void requireInitUIAndData(Bundle savedInstanceState) {

        fetchUserCacheData();
        mUserCheckAdapter = new UserCheckAdapter(R.layout.item_user_cache,userCacheBeanList);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.VERTICAL, false));
        mRecyclerView.setAdapter(mUserCheckAdapter);

    }

    private void fetchUserCacheData() {
        userCacheBeanList.add(new UserCacheBean("customer_id", UserDataManager.getInstance().getCustomerId()));
        userCacheBeanList.add(new UserCacheBean("mobile", UserDataManager.getInstance().getMobile()));
        userCacheBeanList.add(new UserCacheBean("nick_name", UserDataManager.getInstance().getNickName()));
        userCacheBeanList.add(new UserCacheBean("headimgurl", UserDataManager.getInstance().getHeadImgUrl()));
        userCacheBeanList.add(new UserCacheBean("customer_role_level", UserDataManager.getInstance().getRoleLevel()));
        userCacheBeanList.add(new UserCacheBean("invite_code", UserDataManager.getInstance().getInviteCode()));
        if (UserDataManager.getInstance().isAgent()) {
            userCacheBeanList.add(new UserCacheBean("is_agent", "1"));
        } else {
            userCacheBeanList.add(new UserCacheBean("is_agent", "0"));
        }
        userCacheBeanList.add(new UserCacheBean("idcard_real_name", UserDataManager.getInstance().getIdCardRealName()));
        userCacheBeanList.add(new UserCacheBean("idcard_id_number", UserDataManager.getInstance().getIdCardNo()));
        userCacheBeanList.add(new UserCacheBean("check_idcard_message", UserDataManager.getInstance().getIdCardMessage()));
    }

    public static class UserCacheBean {

        public UserCacheBean(String key,String value) {
            this.key = key;
            this.value = value;
        }

        String key;
        String value;

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public static class UserCheckAdapter extends BaseQuickAdapter<UserCacheBean, BaseViewHolder> {

        public UserCheckAdapter(int layoutResId, @Nullable List<UserCacheBean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, UserCacheBean item) {
            TextView key = helper.getView(R.id.user_cache_key);
            TextView value = helper.getView(R.id.user_cache_value);
            key.setText(item.getKey()+":");
            value.setText(item.getValue());
        }
    }

}
